<script>
	import config from './config'
	import store from '@/store'
	import {
		getQueryString
	} from "@/utils/common.js";
	import {
		EventBus
	} from "@/utils/event-bus.js";
	import {
		getToken
	} from '@/utils/auth'
	import storage from '@/utils/storage'
	import {
		getDictType
	} from "@/api/system/public.js";
	export default {
		onLaunch: function() {
			this.initApp()
			this.getMediaType()
			// getDictType({
			// 	dictType: 'WeChat_YB_config'
			// }).then(res => {
			// 	console.log(res)
			// })
		},
		methods: {
			async wxLogin() {
				this.$store.dispatch('WXLogin')
			},
			getMediaType() { //判断一下是微信还是支付宝
				// if (window.navigator.userAgent.indexOf('AlipayClient') > -1) { //支付宝
				var windowUrl = window.location.href;
				var baseUrl = windowUrl.split('/')[3];// 获取公众号配置地址
				var openid = uni.getStorageSync('openid') || '';
				var activeOpenId = baseUrl+openid;
				// 首先，创建一个URL对象
				const wurl = new URL(windowUrl);
				// 使用URLSearchParams获取参数
				const params = new URLSearchParams(wurl.search);
				uni.setStorageSync('baseUrl', baseUrl);
				if(window.location.href.indexOf('wzfPay') > -1 || window.location.href.indexOf('wechatPay') > -1){
					uni.setStorageSync('cardNum', params.get('cardNum'))
				}
				
				if (window.location.href.indexOf('alipay') > -1) {
					//支付宝 扫码支付
					// 获取特定参数的值
					var wParams = {
						auth_code: params.get('auth_code'),
						cardNum: params.get('cardNum'),
						app_id: params.get('app_id')
					}
					var url = '/pages/pay/aliPay/index?wParams='+encodeURIComponent(JSON.stringify(wParams))
					uni.reLaunch({ url: url })
					this.globalData.mediaType = 'zfb';
				}else { //微信
					this.globalData.mediaType = 'wx'
					if (getQueryString('jzjktData')) {
						uni.setStorageSync('userId', getQueryString('jzjktData'))
						uni.setStorageSync('jzjktFunc', getQueryString('jzjktFunc'))
					}
					if (!uni.getStorageSync(activeOpenId) || !uni.getStorageSync('openid') || !uni.getStorageSync('wxinfo')) {
						uni.setStorageSync('hospital','');
						uni.setStorageSync('hospital'+baseUrl,'');
						 this.wxLogin()
					} else {
						if (getQueryString('jzjktFunc') == 'mainpage') {
							setTimeout(() => {
								EventBus.$emit('outSideJump', '')
							}, 1500)
						}
					}
				}
			},
			// 初始化应用
			initApp() {
				// 初始化应用配置
				this.initConfig()
				// 检查用户登录状态
				//#ifdef H5
				// this.checkLogin()
				//#endif
			},
			initConfig() {
				this.globalData.config = config
			},
			checkLogin() {
				if (!getToken()) {
					this.$tab.reLaunch('/pages/index')
				}
			},
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";

	@import '@/static/scss/index.scss';

	::v-deep .uni-tabbar__label {
		font-size: 28rpx !important;

	}
</style>